import { ReqPage, ResPage } from "@/api/interface";
import http from "@/api";
import { SysDeptInfoResult } from "@/api/modules/sys/dept";
import { SysRoleInfoResult } from "@/api/modules/sys/role";

const baseUrl: string = "/sys/user";

export interface SysUserPageParam extends ReqPage {
  nickName: string;
  userStatus: number;
  deptId: string;
  roleIdList: string[];
}

export interface SysUserInfoResult {
  id: string;
  nickName: string;
  email: string;
  mobile: string;
  userStatus: number;
  deptInfo: SysDeptInfoResult;
  roleInfoList: SysRoleInfoResult[];
}

// 获取用户列表
export const getUserList = (params: SysUserPageParam) => {
  return http.get<ResPage<SysUserInfoResult>>(baseUrl + `/page`, params);
};

// 获取自己的登录信息
export const getSelfInfo = () => {
  return http.get<SysUserInfoResult>(baseUrl + `/info`);
};

export const getUserInfo = (id: string) => {
  return http.get<SysUserInfoResult>(baseUrl + `/info/` + id);
};

export interface SysUserSaveParam {
  nickName?: string;
  userName?: string;
  password?: string;
  email?: string;
  mobile?: string;
  userStatus?: number;
  deptId?: string;
  roleIdList?: string[];
}

// 新增用户
export const addUser = (params: SysUserSaveParam) => {
  return http.post(baseUrl + `/save`, params);
};

export interface SysUserUpdateParam {
  id: string;
  nickName?: string;
  userName?: string;
  password?: string;
  email?: string;
  mobile?: string;
  userStatus?: number;
  deptId?: string;
  roleIdList?: string[];
}

// 编辑用户
export const editUser = (params: SysUserUpdateParam) => {
  return http.post(baseUrl + `/update`, params);
};

// 删除用户
export const deleteUser = (params: string[]) => {
  return http.post(baseUrl + `/delete`, params);
};

// 切换用户状态
export const changeUserStatus = (params: { id: string; status: number }) => {
  return http.post(`/user/change`, params);
};

export interface SysUserChangePasswordParam {
  oldPassword: string;
  newPassword: string;
}

/**
 * 修改密码
 */
export const changePassword = (params: SysUserChangePasswordParam) => {
  return http.post(baseUrl + `/change/password`, params);
};

// // 批量添加用户
// export const BatchAddUser = (params: FormData) => {
//   return http.post(`/user/import`, params);
// };

// // 重置用户密码
// export const resetUserPassWord = (params: { id: string }) => {
//   return http.post(`/user/rest_password`, params);
// };
//
// // 导出用户数据
// export const exportUserInfo = (params: User.ReqUserParams) => {
//   return http.download(`/user/export`, params);
// };
//
// // 获取用户状态字典
// export const getUserStatus = () => {
//   return http.get<User.ResStatus[]>(`/user/status`);
// };
//
// // 获取用户性别字典
// export const getUserGender = () => {
//   return http.get<User.ResGender[]>(`/user/gender`);
// };
//
// // 获取用户部门列表
// export const getUserDepartment = () => {
//   return http.get<User.ResDepartment[]>(`/user/department`, {}, { cancel: false });
// };
//
// // 获取用户角色字典
// export const getUserRole = () => {
//   return http.get<User.ResRole[]>(`/user/role`);
// };
